package cn.deepxi.base.service.impl;

import cn.deepxi.base.mapper.BaseMapper;
import cn.deepxi.base.query.BaseQuery;
import cn.deepxi.base.service.IBaseService;

import cn.deepxi.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;
    @Override
    @Transactional
    public void save(T d) {
        baseMapper.save(d);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    @Override
    @Transactional
    public void update(T d) {
        baseMapper.update(d);
    }

    @Override
    public T loadById(Long id) {

        return baseMapper.loadById(id);
    }

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public QueryResult<T> queryPage(BaseQuery baseQuery) {
        //分页及高级查询相关数据
        List<T> data = baseMapper.queryData(baseQuery);
        //总条数（包括高级查询和普通查询）
        Long queryCount = baseMapper.queryCount(baseQuery);
        return new QueryResult<T>(queryCount,data);
    }
}
